package com.ruoyi.web.zangchat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.stereotype.Service;
import com.ruoyi.web.zangchat.mapper.ChatLabelMapper;
import com.ruoyi.web.zangchat.domain.ChatLabel;
import com.ruoyi.web.zangchat.service.IChatLabelService;

/**
 * 标签 服务层实现
 *
 * @author ruoyi
 * @date 2020-07-24
 */
@Service
public class ChatLabelServiceImpl extends ServiceImpl<ChatLabelMapper, ChatLabel> implements IChatLabelService
{

    @Override
    public AjaxResult saveChatLabel(ChatLabel chatLabel) {
        String labelName = chatLabel.getLabelName();
        ChatLabel label = baseMapper.selectOne(new QueryWrapper<ChatLabel>().eq("label_name", labelName));
        if (label!=null){
            return AjaxResult.error(labelName+"已存在");
        }
        baseMapper.insert(chatLabel);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult updateChatLabelById(ChatLabel chatLabel) {
        String labelName = chatLabel.getLabelName();
        ChatLabel label = baseMapper.selectOne(new QueryWrapper<ChatLabel>().eq("label_name", labelName));
        if (label!=null){
            return AjaxResult.error(labelName+"已存在");
        }
        baseMapper.updateById(chatLabel);
        return AjaxResult.success();

    }
}